<!-- 组件：导航Tab名称配置-数据字典 -->
<!-- created by chengfei 2023/4/19 -->
<template>
    <div>
        <a-form-model :model="form" :label-col="{ span: 4 }" :wrapper-col="{ span: 18 }">
            <a-form-model-item prop="dicKey" :label="i18n('dicKey','数据字典项')">
                <a-tree-select v-model="form.dicKey" :treeData="dicTree" />
            </a-form-model-item>
        </a-form-model>
    </div>
</template>

<script>
import SysTreeApi from '@/api/system/core/sysTree'
import { App, Util } from "@lowcode/jpaas-common-lib"
export default {
    name: 'TabTreeSettingDic',
    mixins: [App],
    props: {
        defaultValue: { type: Object, default: () => {} },
    },
    data() {
        return {
            form: {
                dicKey: ''
            },
            dicTree: [],
        }
    },
    mounted() {
        this.loadDicTree()
        this.init()
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"formCodegenBusiness.edit2.TabTreeConfSetting",key);
        },
        loadDicTree() {
            SysTreeApi.listDicTree(this.curApp.appId).then((res) => {
                var cloneData = []
                res.forEach(function (item) {
                    cloneData.push({
                        title: item.name,
                        key: item.treeId,
                        value: item.alias,
                        parentId: item.parentId,
                    })
                })
                var treeData = Util.listToTree(cloneData, 'key', 'parentId')
                this.dicTree = treeData
            })
        },
        init() {
            const { type, setting } = this.defaultValue
            if (type === 'dic') {
                Object.keys(this.form).forEach(key => {
                    this.form[key] = setting[key] || ''
                })
            }
        },
        getData() {
            return this.form
        },
    },
}
</script>

<style scoped></style>
